package cn.signalpha.modules.shop.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.shop.entity.PlaceLevel;
import cn.signalpha.modules.shop.mapper.PlaceLevelMapper;
import cn.signalpha.modules.shop.vo.PlaceLevelVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class PlaceLevelService extends ServiceImpl<PlaceLevelMapper, PlaceLevel> {

	/**
	 * 自定义分页
	 */
    public IPage<PlaceLevelVO> selectPlaceLevelPage(IPage<PlaceLevelVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectPlaceLevelPage(page, params));
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<PlaceLevel> selectPlaceLevelWrapper(Map<String, Object> params) {
        QueryWrapper<PlaceLevel> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("level")), PlaceLevel::getLevel, params.get("level"));
        wrapper.lambda().like(ObjectUtil.isNotEmpty(params.get("name")), PlaceLevel::getName, params.get("name"));
        wrapper.lambda().orderByAsc(PlaceLevel::getLevel).orderByDesc(PlaceLevel::getId);
        return wrapper;
    }

	/**
	 * 等级搜索
	 */
	public PlaceLevel getByLevel(int level) {
		return baseMapper.selectOne(Wrappers.<PlaceLevel>lambdaQuery().eq(PlaceLevel::getLevel, level));
	}

	/**
	 * 名称查询
	 */
	public PlaceLevel getByName(String name) {
		return baseMapper.selectOne(Wrappers.<PlaceLevel>lambdaQuery().eq(PlaceLevel::getName, name));
	}
}

